<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    // 求出1-1/2+1/3-1/4…..1/100的和
    // 分母为偶数就是-，奇数就是+
    var sum = 0
    for (var i = 1; i <= 100; i++) {
      // i%2的结果要么为0，要么为1，1会隐式转换成true，0会隐式转换成false
      if (i % 2) {
        // 奇数
        sum += 1/i
      } else {
        sum -= 1/i
      }
    }
    console.log(sum)
  </script>
</body>
</html>